﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace T17Collection
{
    class Program
    {
        static void Main(string[] args)
        {
            #region 关联性泛型集合(K-V)
            #region Dictionary
            Dictionary<string, Product> dictrProduct = new Dictionary<string, Product>();
            dictrProduct.Add("t1", new Product());
            dictrProduct.Add("t3", new Product());
            dictrProduct.Add("t2", new Product());
            //有效数据的个数
            Console.WriteLine(dictrProduct.Count);
            //获取值
           Product p;
            Console.WriteLine(dictrProduct.TryGetValue("t1",out p));
            //获取键
            foreach (var key in dictrProduct.Keys)
            {
                Console.Write("{0}\t",key);
            }
            Console.WriteLine();
            #endregion Dictionary(哈希表)
            

            #region SortedDictionary (二叉树)
            SortedDictionary<string, Product> sDicProduct = new SortedDictionary<string, Product>();
            sDicProduct.Add("t1", new Product());
            sDicProduct.Add("t3", new Product());
            sDicProduct.Add("t2", new Product());
            Console.WriteLine(sDicProduct.Count);
            Console.WriteLine(sDicProduct.ContainsKey("t10"));
            foreach (var key in sDicProduct.Keys)
            {
                Console.Write("{0}\t",key);
            }
            Console.WriteLine();
            #endregion
            #region SortedList (数组)
            SortedList<string, Product> sListProducts = new SortedList<string, Product>();
            sListProducts.Add("t1", new Product());
            sListProducts.Add("t3", new Product());
            sListProducts.Add("t2", new Product());
            foreach (var key in sListProducts.Keys)
            {
                    Console.Write("{0}\t", key);
            }
                Console.WriteLine();
                Console.WriteLine(sListProducts.ContainsValue(null));
            #endregion
            #endregion

            #region 非关联性泛型集合
            #region List(数组)
            List <Product> lProducts = new List<Product>();
            lProducts.Add(new Product());
            Console.WriteLine(lProducts[0].GetHashCode());
            #endregion
            #region LinkedList(双向链表)
            LinkedList<Product> llProducts = new LinkedList<Product>();
            llProducts.AddLast(new Product("aa", "类型"));
            llProducts.AddFirst(new Product("bb", "类型"));
            foreach (var product in llProducts)
            {
                Console.Write("{0}\t",product.Name);
            }
            Console.WriteLine();
            #endregion
            #region HashSet(哈希表)对象相等的规则（hashcode相同）
            HashSet<Product> hsProducts = new HashSet<Product>();
            hsProducts.Add(new Product("cc", "类型"));
            hsProducts.Add(new Product("aa", "类型"));
            hsProducts.Add(new Product("aa", "类型"));
            hsProducts.Add(new Product("bb", "类型"));
            foreach (var product in hsProducts)
            {
                Console.Write("{0}\t",product.Name);
            }
            Console.WriteLine();
            #endregion
            #region SortedSet (二叉树)
            SortedSet<Product> ssProducts = new SortedSet<Product>();
            ssProducts.Add(new Product("cc ", "类型"));
            ssProducts.Add(new Product("aa ", "类型"));
            ssProducts.Add(new Product("aa ", "类型"));
            ssProducts.Add(new Product("bb ", "类型"));
            foreach (var product in ssProducts)
            {
                Console.Write("{0}\t",product.Name);
            }
            Console.WriteLine();
            #endregion
            #region Stack (栈)
            Stack<Product> sProducts = new Stack<Product>();
            sProducts.Push(new Product("t1 ", "类型"));
            sProducts.Push(new Product("t2 ", "类型"));
            Console.Write(sProducts.Peek().Name);
            Console.Write(sProducts.Pop().Name);
            Console.Write(sProducts.Peek().Name);


            #endregion
            #region Queue (队列)
            Queue<Product> qProducts = new Queue<Product>();
            qProducts.Enqueue(new Product("x1", "类型"));
            qProducts.Enqueue(new Product("x2", "类型"));
            Console.Write(qProducts.Peek().Name);
            Console.Write(qProducts.Dequeue().Name);
            Console.Write(qProducts.Peek().Name);

            #endregion
            #endregion
            Console.ReadKey();
        }
    }
}
